Runs once, when the instance’s slot is actually freed - after Destroy (end of the same frame), or when a non-persistent instance is cleared on a room change.
cleanup: fires once, when the instance’s slot is actually freedRuns once, when this instance's slot is actually freed - after Destroy (at the end of the same frame), or, for a non-persistent instance, when the room it was in stops being current. Both paths free the slot through the same mechanism, so Cleanup's own code cannot tell which one caused it - if that distinction matters, set a flag in Destroy first and read it here.
Persistent instances (persistent) survive a room change, so Cleanup does not run for one on a room change - only on an explicit instance_destroy(), or at shutdown.
In a Persistent room, Cleanup does not run when the player leaves either: the instances are set aside, not removed. It runs for each of them later, if the game forgets the room (the game keeps only so many, or the code called room_forget).
save_set("enemies_remaining", save_get("enemies_remaining", 0) - 1);Updates a saved tally so it stays right regardless of which of the two paths into Cleanup freed this instance's slot.
Via the SAME compile-time hook either way - a project’s own Cleanup code cannot tell which of the two caused it.